package org.example.java_200_question.p01;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author lou ke
 * @since 2024/2/8 20:26
 * 实现Callable接口的方法
 */
public class MyCallable implements Callable<String> {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        FutureTask<String> stringFutureTask = new FutureTask<>(new MyCallable());

        Thread thread = new Thread(stringFutureTask);

        thread.start();

        String s = stringFutureTask.get();

        System.out.println(s);
    }

    @Override
    public String call() throws Exception {
        return "hello callable!";
    }
}
